/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.projetjava.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.*;
import fr.unice.miage.projetjava.entities.Commande;
import fr.unice.miage.projetjava.entities.LigneDePanier;
import java.util.Collection;

/**
 *
 * @author Olivier
 */
public class Dialog2 extends DialogBox {

    FlexTable tableButton = new FlexTable();
    FlexTable table = new FlexTable();

    public static MenuClientTestAsync getService() {
        // Create the client proxy. Note that although you are creating the
        // service interface proper, you cast the result to the asynchronous
        // version of
        // the interface. The cast is always safe because the generated proxy
        // implements the asynchronous interface automatically.
        MenuClientTestAsync service = (MenuClientTestAsync) GWT.create(MenuClientTest.class);
        // Specify the URL at which our service implementation is running.
        // Note that the target URL must reside on the same domain and port from
        // which the host page was served.
        //
        ServiceDefTarget endpoint = (ServiceDefTarget) service;
        String moduleRelativeURL = GWT.getModuleBaseURL() + "menuclienttest";
        endpoint.setServiceEntryPoint(moduleRelativeURL);
        return service;
    }

    Dialog2(Collection<Commande> listCommande) {
        setText("Commande");
        table.setText(0, 0, "Ref commande");
        table.setText(0, 1, "Date");
        int i = 1;
        for (Commande lc : listCommande) {
            table.setText(i, 0, String.valueOf(lc.getId()));
            table.setText(i, 1, String.valueOf(lc.getDateDeCommande()));
            i++;
        }
        Button closeButton = new Button("Quitter");
        tableButton.setWidget(0, 0, closeButton);
        HTML msg = new HTML("<center>Historique de vos commandes</center>", true);

        DockPanel dock = new DockPanel();
        dock.setSpacing(4);

        dock.add(tableButton, DockPanel.SOUTH);
        dock.add(msg, DockPanel.NORTH);
        dock.add(table, DockPanel.CENTER);

        dock.setCellHorizontalAlignment(tableButton, DockPanel.ALIGN_CENTER);
        dock.setCellWidth(table, "100%");
        dock.setWidth("100%");
        dock.setHeight("100%");
        table.setWidth("36em");
        table.setHeight("20em");

        final AsyncCallback callbackInscription = new AsyncCallback() {

            public void onSuccess(Object result) {
                hide();
            }

            public void onFailure(Throwable caught) {
            }
        };

        closeButton.addClickListener(new ClickListener() {

            public void onClick(Widget w) {
                hide();
            }
        });

        setWidget(dock);
    }

}
